home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '87 / Source ƒ.sea / Source ƒ / emacs source ƒ / TCAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  4.1 KB  |  229 lines  |  [TEXT/MARC]

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for MicroEMACS
  3. */
  4.  
  5. #define    termdef    1            /* don't define "term" external */
  6.  
  7. #include <stdio.h>
  8. #include    "estruct.h"
  9. #include        "edef.h"
  10.  
  11. #if TERMCAP
  12.  
  13. #define    MARGIN    8
  14. #define    SCRSIZ    64
  15. #define    NPAUSE    10            /* # times thru update to pause */
  16. #define BEL     0x07
  17. #define ESC     0x1B
  18.  
  19. extern int      ttopen();
  20. extern int      ttgetc();
  21. extern int      ttputc();
  22. extern int    tgetnum();
  23. extern int      ttflush();
  24. extern int      ttclose();
  25. extern int    tcapkopen();
  26. extern int    tcapkclose();
  27. extern int      tcapmove();
  28. extern int      tcapeeol();
  29. extern int      tcapeeop();
  30. extern int      tcapbeep();
  31. extern int    tcaprev();
  32. extern int      tcapopen();
  33. extern int      tput();
  34. extern char     *tgoto();
  35. #if    COLOR
  36. extern    int    tcapfcol();
  37. extern    int    tcapbcol();
  38. #endif
  39.  
  40. #define TCAPSLEN 315
  41. char tcapbuf[TCAPSLEN];
  42. char *UP, PC, *CM, *CE, *CL, *SO, *SE;
  43.  
  44. TERM term = {
  45.     NULL,        /* these two values are set dynamically at open time */
  46.     NULL,
  47.     MARGIN,
  48.     SCRSIZ,
  49.     NPAUSE,
  50.         tcapopen,
  51.         ttclose,
  52.         tcapkopen,
  53.         tcapkclose,
  54.         ttgetc,
  55.         ttputc,
  56.         ttflush,
  57.         tcapmove,
  58.         tcapeeol,
  59.         tcapeeop,
  60.         tcapbeep,
  61.         tcaprev
  62. #if    COLOR
  63.     , tcapfcol,
  64.     tcapbcol
  65. #endif
  66. };
  67.  
  68. tcapopen()
  69.  
  70. {
  71.         char *getenv();
  72.         char *t, *p, *tgetstr();
  73.         char tcbuf[1024];
  74.         char *tv_stype;
  75.         char err_str[72];
  76.  
  77.         if ((tv_stype = getenv("TERM")) == NULL)
  78.         {
  79.                 puts("Environment variable TERM not defined!");
  80.                 exit(1);
  81.         }
  82.  
  83.         if ((tgetent(tcbuf, tv_stype)) != 1)
  84.         {
  85.                 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
  86.                 puts(err_str);
  87.                 exit(1);
  88.         }
  89.  
  90.  
  91.        if ((term.t_nrow=(short)tgetnum("li")-1) == -1){
  92.                puts("termcap entry incomplete (lines)");
  93.                exit(1);
  94.        }
  95.  
  96.        if ((term.t_ncol=(short)tgetnum("co")) == -1){
  97.                puts("Termcap entry incomplete (columns)");
  98.                exit(1);
  99.        }
  100.  
  101.         p = tcapbuf;
  102.         t = tgetstr("pc", &p);
  103.         if(t)
  104.                 PC = *t;
  105.  
  106.         CL = tgetstr("cl", &p);
  107.         CM = tgetstr("cm", &p);
  108.         CE = tgetstr("ce", &p);
  109.         UP = tgetstr("up", &p);
  110.     SE = tgetstr("se", &p);
  111.     SO = tgetstr("so", &p);
  112.     if (SO != NULL)
  113.         revexist = TRUE;
  114.  
  115.         if(CL == NULL || CM == NULL || UP == NULL)
  116.         {
  117.                 puts("Incomplete termcap entry\n");
  118.                 exit(1);
  119.         }
  120.  
  121.     if (CE == NULL)        /* will we be able to use clear to EOL? */
  122.         eolexist = FALSE;
  123.         
  124.         if (p >= &tcapbuf[TCAPSLEN])
  125.         {
  126.                 puts("Terminal description too big!\n");
  127.                 exit(1);
  128.         }
  129.         ttopen();
  130. }
  131.  
  132. tcapkopen()
  133.  
  134. {
  135. }
  136.  
  137. tcapkclose()
  138.  
  139. {
  140. }
  141.  
  142. tcapmove(row, col)
  143. register int row, col;
  144. {
  145.         putpad(tgoto(CM, col, row));
  146. }
  147.  
  148. tcapeeol()
  149. {
  150.         putpad(CE);
  151. }
  152.  
  153. tcapeeop()
  154. {
  155.         putpad(CL);
  156. }
  157.  
  158. tcaprev(state)        /* change reverse video status */
  159.  
  160. int state;        /* FALSE = normal video, TRUE = reverse video */
  161.  
  162. {
  163.     static int revstate = FALSE;
  164.     /* mustn't send SE unless SO already sent, and vice versa */
  165.  
  166. #if 0
  167.     if (state) {
  168.         if ((SO != NULL) && (revstate == FALSE))
  169.             putpad(SO);
  170.     } else
  171.         if ((SE != NULL) && (revstate == TRUE))
  172.             putpad(SE);
  173.  
  174.     revstate = state;
  175. #endif
  176.     if (state) {
  177.         if (SO != NULL)
  178.             putpad(SO);
  179.     } else
  180.         if (SE != NULL)
  181.             putpad(SE);
  182. }
  183.  
  184. #if    COLOR
  185. tcapfcol()    /* no colors here, ignore this */
  186. {
  187. }
  188.  
  189. tcapbcol()    /* no colors here, ignore this */
  190. {
  191. }
  192. #endif
  193.  
  194. tcapbeep()
  195. {
  196.     ttputc(BEL);
  197. }
  198.  
  199. putpad(str)
  200. char    *str;
  201. {
  202.     tputs(str, 1, ttputc);
  203. }
  204.  
  205. putnpad(str, n)
  206. char    *str;
  207. {
  208.     tputs(str, n, ttputc);
  209. }
  210.  
  211.  
  212. #if    FLABEL
  213. fnclabel(f, n)        /* label a function key */
  214.  
  215. int f,n;    /* default flag, numeric argument [unused] */
  216.  
  217. {
  218.     /* on machines with no function keys...don't bother */
  219.     return(TRUE);
  220. }
  221. #endif
  222. #else
  223.  
  224. hello()
  225. {
  226. }
  227.  
  228. #endif TERMCAP
  229.